﻿/* Write methods to calculate minimum, maximum, average, sum and product of 
 * given set of integer numbers. Use variable number of arguments.*/




using System;
using System.Globalization;
using System.Threading;

class MinMaxAVSumPr
{
    static void Main()
    {
        Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
        uint N;
        bool iProvided = false;
        do
        {
            if (iProvided == true) Console.WriteLine("Error! Please enter a positive integer number!\r\n\tValid value range is from 1 to {0}", UInt32.MaxValue);
            else iProvided = true;
            Console.Write("Please enter how many numbers will your sequence contain!: ");
        } while (UInt32.TryParse(Console.ReadLine(), out N) == false || N < 1);


        int[] nums = new int[N];
        for (int i = 0; i < nums.Length; i++)
        {
            iProvided = false; //reset iProvided to avoid getting a "false negative" error type

            do
            {
                if (iProvided == true) Console.WriteLine("Error! Please enter an integer number!\r\n\tValid value range is from {1} to {0}", UInt32.MaxValue, UInt32.MinValue);
                else iProvided = true;
                Console.Write("Please enter element number #{0}: ", i+1);
            } while (Int32.TryParse(Console.ReadLine(), out nums[i]) == false);
        }
        Console.WriteLine("Minimum: {0}\r\nMaximum: {1}\r\nAverage: {2}\r\nSum: {3}\r\nProduct: {4}", Getminel(nums), Getmaxel(nums), CalculateAverage(nums), CalculateSum(nums), CalculateProduct(nums));
    }

    private static int CalculateProduct(int[] numseq)
    {
        int sum = 1;
        foreach (var e in numseq) sum *= e;
        return sum;
    }

    private static int CalculateSum(int[] numseq)
    {
        int sum = 0;
        foreach (var e in numseq) sum += e;
        return sum;
    }
    private static double CalculateAverage(int[] numseq)
    {
        int sum = 0;
        for (int i = 0; i < numseq.Length; i++)
        {
            sum += numseq[i];
        }

        return (double)sum / (double)numseq.Length;
    }
    /* method to get the maximal elements in an array by starting at given index 
 parameters: int[] nums - the array we want to search in
 start: the index we want to start at
 */
    private static int Getmaxel(int[] numseq, int start = 0)
    {
        if (start > numseq.Length - 1) throw new IndexOutOfRangeException(); //throw an error on invalid argument

        int max = int.MinValue;
        for (int i = start; i < numseq.Length; i++)
        {
            if (numseq[i] > max) max = numseq[i];
        }
        return max;
    }
    private static int Getminel(int[] numseq, int start = 0)
    {
        if (start > numseq.Length - 1) throw new IndexOutOfRangeException(); //throw an error on invalid argument

        int min = int.MaxValue;
        for (int i = start; i < numseq.Length; i++)
        {
            if (numseq[i] < min) min = numseq[i];
        }
        return min;
    }



}
